import "package:flutter/material.dart";

import './calendar/calendar.dart';
import './calendar/event.dart';
import './calendar/events.dart';


class CalendarPage0 extends StatefulWidget {
    final String text;
    
    CalendarPage0({Key key, this.text}) : super(key: key);
    
    @override
    _CalendarPage0State createState() => _CalendarPage0State();
}

class _CalendarPage0State extends State<CalendarPage0> {
    PreferredSize appBar;
    
    EventList<Event> _eventDatesMap = new EventList<Event>(
        events: {
            DateTime(2019, 8, 10): [
                Event(
                    date: DateTime(2019, 8, 10),
                    title: 'Learning C#',
                    style : TextStyle(
                        color: Colors.red,
                    ),
                ),
                Event(
                    date: DateTime(2019, 8, 10),
                    title: 'Learning JavaScript',
                ),
                Event(
                    date: DateTime(2019, 8, 10),
                    title: 'Learning Flutter',
                ),
                Event(
                    date: DateTime(2019, 8, 10),
                    title: 'Learning C#',
                ),
                Event(
                    date: DateTime(2019, 8, 10),
                    title: 'Learning JavaScript',
                ),
                Event(
                    date: DateTime(2019, 8, 10),
                    title: 'Learning Flutter',
                ),
            ],
            DateTime(2019, 8, 22): [
                Event(
                    date: DateTime(2019, 8, 22),
                    title: 'C#',
                ),
                Event(
                    date: DateTime(2019, 8, 22),
                    title: 'JavaScript',
                ),
                Event(
                    date: DateTime(2019, 8, 22),
                    title: 'Flutter',
                ),
            ],
        },
    );
    
    @override
    void initState() {
        super.initState();
    }
    
    @override
    dispose() {
        super.dispose();
    }
    
    @override
    Widget build(BuildContext context) {
        appBar = PreferredSize(
            preferredSize: Size.fromHeight(36.0),
            child: AppBar(
                centerTitle: true,
                elevation: 0.5,
                titleSpacing: 0.0,
                title: Text(widget.text),
            ),
        );
        return Scaffold(
            appBar: appBar,
            body: Container(
                margin: EdgeInsets.only(bottom: MediaQuery
                    .of(context)
                    .padding
                    .bottom),
                child: CalendarView(
                    viewType: ViewType.month,
                    //viewSize: getPageSize(),
                    eventDatesMap: _eventDatesMap,
                    //eventWidget:(event, isToday, isSelectedDay, isThisMonthDay){
                        // print(event.title);
                        // print(isToday);
                        // print(isSelectedDay);
                        //return Text(event.title, maxLines: 1,);
                    //},
                    dateWidget:(date, isToday, isSelectedDay, isThisMonthDay){
                        var day = date.day.toString();
                        return Text(day, maxLines: 1, style: TextStyle(
                            color: (day == '1' || day == '10') ? Colors.amber : Colors.black
                        ),);
                    },
                    onDayPressed : (date, isToday){
                        print(date);
                        print(isToday);
                    },
                    onCalendarChanged : (date){
                        print(date);
                    },
                    // viewSize: Size(MediaQuery.of(context).size.width, 180),
                ),
            ),
        );
    }
    
    Size getPageSize() {
        var appBarHeight = appBar.preferredSize.height;
        // print('appBar       : ${AppBar()}');
        // print('appBarHeight : $appBarHeight');
        double safeAreaTop = MediaQuery
            .of(context)
            .padding
            .top;
        double safeAreaBottom = MediaQuery
            .of(context)
            .padding
            .bottom;
        double screenWidth = MediaQuery
            .of(context)
            .size
            .width;
        double screenHeight = MediaQuery
            .of(context)
            .size
            .height;
        double pageWidth = screenWidth;
        double pageHeight = screenHeight - safeAreaTop - appBarHeight - safeAreaBottom;
        // print('   safeAreaTop : $safeAreaTop');
        // print('safeAreaBottom : $safeAreaBottom');
        // print('        appBar : ${appBar.preferredSize.height}');
        // print('    pageHeight : $pageHeight');
        return Size(pageWidth, pageHeight);
    }
    
}
